package jp.eisbahn.mgapi.auth;

import javax.servlet.http.HttpServletResponse;

/**
 * This class has the information of tokens used to access mixi Graph API.
 * @author Yoichiro Tanaka
 */
public class Token {

    /** The flag whether the access is successfuly or not. */
    private boolean success;
    /** The refresh token. */
    private String refreshToken;
    /** The access token. */
    private String accessToken;
    /** The term of the access token. */
    private long expiresIn;
    /** The status code. */
    private int statusCode;
    /** The status message. */
    private String statusMessage;

    /**
     * Initialize this instance.
     * @param newRefreshToken The refresh token.
     * @param newAccessToken The access token.
     * @param newExpiresIn The term of the access token.
     */
    public Token(final String newRefreshToken,
            final String newAccessToken, final long newExpiresIn) {
        super();
        success = true;
        refreshToken = newRefreshToken;
        accessToken = newAccessToken;
        expiresIn = newExpiresIn;
        statusCode = HttpServletResponse.SC_OK;
        statusMessage = "OK";
    }

    /**
     * Initialize this instance.
     * @param newStatusCode The status code.
     * @param newMessage The status message.
     */
    public Token(final int newStatusCode, final String newMessage) {
        super();
        success = false;
        statusCode = newStatusCode;
        statusMessage = newMessage;
    }

    /**
     * Retrieve the refresh token.
     * @return The refresh token string.
     */
    public final String getRefreshToken() {
        return refreshToken;
    }

    /**
     * Retrieve the access token.
     * @return  The access token string.
     */
    public final String getAccessToken() {
        return accessToken;
    }

    /**
     * Retrieve the term of the access token.
     * @return The term value.
     */
    public final long getExpiresIn() {
        return expiresIn;
    }

    /**
     * Retrieve whether the access of API is successful or not.
     * @return If succeed, return true.
     */
    public final boolean isSuccess() {
        return success;
    }

    /**
     * Retrieve the status code.
     * @return The status code value.
     */
    public final int getStatusCode() {
        return statusCode;
    }

    /**
     * Retrieve the status message.
     * @return The human-readable status message string.
     */
    public final String getStatusMessage() {
        return statusMessage;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public final String toString() {
        return "Token [success=" + success + ", refreshToken=" + refreshToken
                + ", accessToken=" + accessToken + ", expiresIn=" + expiresIn
                + ", statusCode=" + statusCode + ", statusMessage="
                + statusMessage + "]";
    }

}
